<!--suppress ALL -->
<include file="./Template/header.html" />

<link rel="stylesheet" type="text/css" href="/Template/css/workorder.css?v=5">
<script type="text/javascript" src="/Template/js/amazeui.js"></script>
<script type="text/javascript">


    $(function() {

        //初始化页面配置
        initPage("工单信息");

        var app = new Vue({
            el: '#container',
            data: {
                number: 1,
            },
            methods: {
                checkRole: function(employeeRoleId, roleId) {
                    var employeeRoleArr = employeeRoleId.split(",");
                    var roleArr = roleId.split(",");

                    var result = false;
                    $.each(roleArr, function(i,val){
                        if($.inArray(val, employeeRoleArr) != -1 || $.inArray((parseInt(val)+100).toString(), employeeRoleArr) != -1){
                            result = true;
                        }
                    });
                    return result;
                },
                patientInfo: function(workorderId) {
                    window.location.href = "/wechat/workorder/patientInfo?workorderId="+workorderId;
                },
                examBasic: function(workorderId) {
                    if("{$workorder.workorder_type}" == "1"){
                        window.location.href = "/wechat/workorder/examBasic?workorderId="+workorderId;
                    }
                    if("{$workorder.workorder_type}" == "2"){
                        window.location.href = "/wechat/workorder/examBasicSpine?workorderId="+workorderId;
                    }
                    if("{$workorder.workorder_type}" == "3"){
                        window.location.href = "/wechat/workorder/examBasicCP?workorderId="+workorderId;
                    }
                    if("{$workorder.workorder_type}" == "4"){
                        window.location.href = "/wechat/workorder/examBasicSco?workorderId="+workorderId;
                    }
                    if("{$workorder.workorder_type}" == "5" || "{$workorder.workorder_type}" == "6"){
                        window.location.href = "/wechat/workorder/examBasicKafo?workorderId="+workorderId;
                    }
                    if("{$workorder.workorder_type}" == "7"){
                        window.location.href = "/wechat/workorder/examBasicFo?workorderId="+workorderId;
                    }
                    if("{$workorder.workorder_type}" == "8"){
                        window.location.href = "/wechat/workorder/examBasicThigh?workorderId="+workorderId;
                    }
                    if("{$workorder.workorder_type}" == "9"){
                        window.location.href = "/wechat/workorder/examBasicShank?workorderId="+workorderId;
                    }
                },
                examBasicCP: function(workorderId) {
                    if("{$workorder.workorder_type}" == "1"){
                        window.location.href = "/wechat/workorder/examBasicCP?workorderId="+workorderId;
                    }
                    if("{$workorder.workorder_type}" == "2"){
                        window.location.href = "/wechat/workorder/examBasicSpine?workorderId="+workorderId;
                    }
                    if("{$workorder.workorder_type}" == "3"){
                        window.location.href = "/wechat/workorder/examBasicCP?workorderId="+workorderId;
                    }
                },
                examMeasure: function(workorderId) {
                    if("{$workorder.workorder_type}" == "1"){
                        window.location.href = "/wechat/workorder/examMeasure?workorderId="+workorderId;
                    }
                    if("{$workorder.workorder_type}" == "2"){
                        window.location.href = "/wechat/workorder/examMeasureSpine?workorderId="+workorderId;
                    }
                    if("{$workorder.workorder_type}" == "4"){
                        window.location.href = "/wechat/workorder/examMeasureSco?workorderId="+workorderId;
                    }
                    if("{$workorder.workorder_type}" == "5" || "{$workorder.workorder_type}" == "6"){
                        window.location.href = "/wechat/workorder/examMeasureKafo?workorderId="+workorderId;
                    }
                    if("{$workorder.workorder_type}" == "7"){
                        window.location.href = "/wechat/workorder/examMeasureFo?workorderId="+workorderId;
                    }
                    if("{$workorder.workorder_type}" == "8"){
                        window.location.href = "/wechat/workorder/examMeasureThigh?workorderId="+workorderId;
                    }
                    if("{$workorder.workorder_type}" == "9"){
                        window.location.href = "/wechat/workorder/examMeasureShank?workorderId="+workorderId;
                    }
                },
                examMeasureSpineDraw: function(workorderId) {
                        window.location.href = "/wechat/workorder/examMeasureSpineDraw?workorderId="+workorderId;

                },
                examAnalysis: function(workorderId) {
                    window.location.href = "/wechat/workorder/examAnalysis?workorderId="+workorderId;
                },
                returnOrder: function() {
                    window.location.href = "/wechat/workflow/index/type/{$workorder.workorder_type}";
                },
                changeStatus: function() {
                    var workorderId = $("input[name=workorderId]").val();
                    var typeName = $("input[name=typeName]").val();
                    var deposit = $("input[name=depositOri]").val();
                    var salesId = $("select[name=salesId]").val();
                    var examinatorId = $("select[name=examinatorId]").val();
                    var prescriberId = $("select[name=prescriberId]").val();
                    var creatorId = $("select[name=creatorId]").val();
                    var price = $("input[name=price]").val();
                    var deliveryDate = $("input[name=deliveryDate]").val();
                    var adapt = $("select[name=adapt]").val();
                    var statusId = $("select[name=statusId]").val();

                    if(!confirm("请确认是否修改状态？")){
                        return false;
                    }

                    var data = {};

                    data.workorderId = workorderId;
                    data.salesId = salesId;
                    data.examinatorId = examinatorId;
                    data.prescriberId = prescriberId;
                    data.creatorId = creatorId;
                    data.typeName = typeName;
                    data.deposit = deposit;
                    data.price = price;
                    data.deliveryDate = deliveryDate;
                    data.adapt = adapt;
                    data.statusId = statusId;

                    $.ajax({
                        url:"/wechat/workorder/changeStatus",
                        type:"post",
                        data:data,
                        dataType:"JSON",
                        beforeSend:function(){
                            $("#loadingToast").show();
                        },
                        complete:function(){
                            $('#loadingToast').hide();
                        },
                        success:function(data){
                            if(data.code != 200) {
                                alert(data.msg);
                                return false;
                            }else{
                                alert("修改工单状态成功");
                            }
//                            window.localStorage.setItem("orderData", null);
//                            window.localStorage.setItem("measureData", null);
                            window.location.href = "/wechat/workflow/index/type/{$workorder.workorder_type}";
                        },
                    })

                },
                /*
                createOrder: function() {
                    var workorderId = $("input[name=workorderId]").val();
                    var patientCompleted = $("input[name=patientCompleted]").val();
                    var examBasicCompleted = $("input[name=examBasicCompleted]").val();
                    var examMeasureCompleted = $("input[name=examMeasureCompleted]").val();
//                    var examMeasureCompleted2 = $("input[name=examMeasureCompleted2]").val();
                    var examAnalysisCompleted = $("input[name=examAnalysisCompleted]").val();
                    var salesId = $("select[name=salesId]").val();

                    if(isNullOrEmpty(patientCompleted)) {
                        alert("患者基本资料未完善");
                        return false;
                    }
//                    if(isNullOrEmpty(examBasicCompleted)) {
//                        alert("检测(评估)信息未完善");
//                        return false;
//                    }
//                    if(isNullOrEmpty(examMeasureCompleted)) {
//                        alert("检测(测量)信息未完善");
//                        return false;
//                    }
//                    if(isNullOrEmpty(examAnalysisCompleted)) {
//                        alert("检测(处方)信息未完善");
//                        return false;
//                    }

                    if(isNullOrEmpty(salesId)) {
                        alert("未选择销售");
                        return false;
                    }
                    if(!confirm("提交后，工单内容只能由临床部进行完善或修改，是否继续？")){
                        return false;
                    }
                    var data = {};

                    data.workorderId = workorderId;
                    data.patientCompleted = patientCompleted;
//                    data.examBasicCompleted = examBasicCompleted;
//                    data.examMeasureCompleted = examMeasureCompleted;
//                    data.examAnalysisCompleted = examAnalysisCompleted;
                    data.salesId = salesId;

                    $.ajax({
                        url:"/wechat/workorder/createOrder",
                        type:"post",
                        data:data,
                        dataType:"JSON",
                        beforeSend:function(){
                            $("#loadingToast").show();
                        },
                        complete:function(){
                            $('#loadingToast').hide();
                        },
                        success:function(data){
                            if(data.code != 200) {
                                alert(data.msg);
                                return false;
                            }else{
                                alert("工单提交成功");
                            }
//                            window.localStorage.setItem("orderData", null);
//                            window.localStorage.setItem("measureData", null);
                            window.location.href = "/wechat/workflow/index/type/{$workorder.workorder_type}";
                        },
                    })

                },
                */
                createOrder: function() {
                    var workorderId = $("input[name=workorderId]").val();
                    var patientCompleted = $("input[name=patientCompleted]").val();
                    var examBasicCompleted = $("input[name=examBasicCompleted]").val();
                    var examBasicCPCompleted = $("input[name=examBasicCPCompleted]").val();
                    var examMeasureCompleted = $("input[name=examMeasureCompleted]").val();
//                    var examMeasureCompleted2 = $("input[name=examMeasureCompleted2]").val();
                    var examAnalysisCompleted = $("input[name=examAnalysisCompleted]").val();
                    var typeName = $("input[name=typeNameOri]").val();
                    var price = $("input[name=price]").val();
                    var salesId = $("select[name=salesId]").val();
                    var examinatorId = $("select[name=examinatorId]").val();
                    var prescriberId = $("select[name=prescriberId]").val();
                    var paymentStatus = $("select[name=paymentStatus]").val();
                    var deposit = $("input[name=deposit]").val();
                    var adapt = $("select[name=adapt]").val();
                    var client_info_id = $("select[name=client_info_id]").val();
                    var receiveName = $("input[name=receiveName]").val();
                    var receiveContact = $("input[name=receiveContact]").val();
                    var receiveAddress = $("input[name=receiveAddress]").val();
                    var deliveryDate = $("input[name=deliveryDate]").val();
                    var typeName = $("input[name=typeName]").val();
//                    if(isNullOrEmpty(patientCompleted)) {
//                        alert("患者基本资料未完善");
//                        return false;
//                    }
//
//                    if(isNullOrEmpty(examBasicCompleted)) {
//                        alert("检测(评估)信息未完善");
//                        return false;
//                    }
//                    if(isNullOrEmpty(examBasicCPCompleted)) {
//                        alert("检测(物理)信息未完善");
//                        return false;
//                    }
                    if("{$workorder.workorder_type}" != "3"){
//                        if(isNullOrEmpty(examMeasureCompleted)) {
//                            alert("检测(测量)信息未完善");
//                            return false;
//                        }
                        if(isNullOrEmpty(prescriberId)) {
                            alert("未选择处方师");
                            return false;
                        }
                        if(isNullOrEmpty(salesId)) {
                            alert("未选择业务员");
                            return false;
                        }
                        if(isNullOrEmpty(examinatorId)) {
                            alert("未选择检测评估矫形师");
                            return false;
                        }
                        if(isNullOrEmpty(price)) {
                            alert("未填写订单价格");
                            return false;
                        }
                        if(isNullOrEmpty(paymentStatus)) {
                            alert("未选择付款情况");
                            return false;
                        }
                        if(paymentStatus == "已付定金" && isNullOrEmpty(deposit)) {
                            alert("未填写定金金额");
                            return false;
                        }
                        if(isNullOrEmpty(adapt)) {
                            alert("未选择适配方式");
                            return false;
                        }
                        if(adapt == "快递") {
                            if(isNullOrEmpty(receiveName)) {
                                alert("未填写收货人姓名");
                                return false;
                            }
                            if(isNullOrEmpty(receiveContact)) {
                                alert("未填写收货人电话");
                                return false;
                            }
                            if(isNullOrEmpty(receiveAddress)) {
                                alert("未填写收货地址");
                                return false;
                            }
                        }

                        var duplicate = 0;
                        if ($("#duplicate").is(":checked")) {
                            if(!confirm("勾选复制后，在创建工单后将复制本工单内容并生成对侧患肢工单，是否继续？")){
                                return false;
                            }
                            duplicate = 1;
                        }

                        if(!confirm("提交后，工单内容如需再次修改请事先通知处方人，是否继续？")){
                            return false;
                        }
                    }else{
                        if(!confirm("提交后，脑瘫物理检查表将无法进行完善或修改，是否继续？")){
                            return false;
                        }
                    }


                    $(".save-btn").hide();

                    var data = {};

                    data.workorderId = workorderId;
                    data.patientCompleted = patientCompleted;
                    data.examBasicCompleted = examBasicCompleted;
                    data.examBasicCompleted = examBasicCPCompleted;
                    data.examMeasureCompleted = examMeasureCompleted;
//                    data.examAnalysisCompleted = examAnalysisCompleted;
                    data.salesId = salesId;
                    data.examinatorId = examinatorId;
                    data.prescriberId = prescriberId;
                    data.typeName = typeName;
                    data.deposit = deposit;
                    data.price = price;
                    data.paymentStatus = paymentStatus;
                    data.adapt = adapt;
                    data.client_info_id = client_info_id;
                    data.receiveName = receiveName;
                    data.receiveContact = receiveContact;
                    data.receiveAddress = receiveAddress;
                    data.duplicate = duplicate;
                    data.deliveryDate = deliveryDate;
                    data.typeName = typeName;

                    $.ajax({
                        url:"/wechat/workorder/createOrder",
                        type:"post",
                        data:data,
                        dataType:"JSON",
                        beforeSend:function(){
                            $("#loadingToast").show();
                        },
                        complete:function(){
                            $('#loadingToast').hide();
                        },
                        success:function(data){
                            if(data.code != 200) {
                                alert("提交失败:"+data.msg);
                                return false;
                            }else{
                                alert("工单提交成功");
                            }
//                            window.localStorage.setItem("orderData", null);
//                            window.localStorage.setItem("measureData", null);
                            window.location.href = "/wechat/workflow/index/type/{$workorder.workorder_type}";
                        },
                        error:function(data){
                            alert("提交失败");
                        }
                    })

                },

                dispatchOrder: function() {
                    var workorderId = $("input[name=workorderId]").val();
//                    var patientCompleted = $("input[name=patientCompleted]").val();
//                    var examBasicCompleted = $("input[name=examBasicCompleted]").val();
//                    var examMeasureCompleted = $("input[name=examMeasureCompleted]").val();
//                    var examAnalysisCompleted = $("input[name=examAnalysisCompleted]").val();
//                    var examinatorId = $("select[name=examinatorId]").val();

//                    if(isNullOrEmpty(patientCompleted)) {
//                        alert("患者基本资料未完善");
//                        return false;
//                    }
//                    if(isNullOrEmpty(examBasicCompleted)) {
//                        alert("检测(评估)信息未完善");
//                        return false;
//                    }
//                    if(isNullOrEmpty(examMeasureCompleted)) {
//                        alert("检测(测量)信息未完善");
//                        return false;
//                    }
//                    if(isNullOrEmpty(examAnalysisCompleted)) {
//                        alert("检测(处方)信息未完善");
//                        return false;
//                    }
//                    if(isNullOrEmpty(examinatorId)) {
//                        alert("未选择检测评估矫形师");
//                        return false;
//                    }
                    var data = {};

                    data.workorderId = workorderId;
//                    data.patientCompleted = patientCompleted;
//                    data.examBasicCompleted = examBasicCompleted;
//                    data.examMeasureCompleted = examMeasureCompleted;
//                    data.examAnalysisCompleted = examAnalysisCompleted;
//                    data.examinatorId = examinatorId;

                    $.ajax({
                        url:"/wechat/workorder/dispatchOrder",
                        type:"post",
                        data:data,
                        dataType:"JSON",
                        beforeSend:function(){
                            $("#loadingToast").show();
                        },
                        complete:function(){
                            $('#loadingToast').hide();
                        },
                        success:function(data){
                            if(data.code != 200) {
                                alert(data.msg);
                                return false;
                            }else{
                                alert("派单成功");
                            }
//                            window.localStorage.setItem("orderData", null);
//                            window.localStorage.setItem("measureData", null);
                            window.location.href = "/wechat/workflow/index/type/{$workorder.workorder_type}";
                        },
                    })

                },
                takeOrder: function() {
                    var workorderId = $("input[name=workorderId]").val();
//                    var patientCompleted = $("input[name=patientCompleted]").val();
                    var examBasicCompleted = $("input[name=examBasicCompleted]").val();
                    var examBasicCPCompleted = $("input[name=examBasicCPCompleted]").val();
                    var examMeasureCompleted = $("input[name=examMeasureCompleted]").val();
//                    var examMeasureCompleted2 = $("input[name=examMeasureCompleted2]").val();
//                    var examAnalysisCompleted = $("input[name=examAnalysisCompleted]").val();
                    var examinatorId = $("select[name=examinatorId]").val();
                    var prescriberId = $("select[name=prescriberId]").val();
                    var batchNo = $("input[name=batchNo]").val();

                    if(isNullOrEmpty(examinatorId)) {
                        alert("未选择检测评估矫形师");
                        return false;
                    }
                    if(examinatorId == -1){
                        if(isNullOrEmpty(examBasicCompleted)) {
                            alert("检测(评估)信息未完善");
                            return false;
                        }
//                        if(isNullOrEmpty(examBasicCPCompleted)) {
//                            alert("检测(物理)信息未完善");
//                            return false;
//                        }
                        if(isNullOrEmpty(examMeasureCompleted)) {
                            alert("检测(测量)信息未完善");
                            return false;
                        }
//                        if(isNullOrEmpty(examMeasureCompleted2) && "{$workorder.workorder_type}" == 2) {
//                            alert("数字化绘制未完善");
//                            return false;
//                        }
                    }
//                    if(isNullOrEmpty(patientCompleted)) {
//                        alert("患者基本资料未完善");
//                        return false;
//                    }
//                    if(isNullOrEmpty(examAnalysisCompleted)) {
//                        alert("检测(处方)信息未完善");
//                        return false;
//                    }

                    var data = {};

                    data.workorderId = workorderId;
//                    data.patientCompleted = patientCompleted;
//                    data.examBasicCompleted = examBasicCompleted;
//                    data.examMeasureCompleted = examMeasureCompleted;
//                    data.examAnalysisCompleted = examAnalysisCompleted;
                    data.examinatorId = examinatorId;
                    data.prescriberId = prescriberId;
                    data.batchNo = batchNo;

                    $.ajax({
                        url:"/wechat/workorder/takeOrder",
                        type:"post",
                        data:data,
                        dataType:"JSON",
                        beforeSend:function(){
                            $("#loadingToast").show();
                        },
                        complete:function(){
                            $('#loadingToast').hide();
                        },
                        success:function(data){
                            if(data.code != 200) {
                                alert(data.msg);
                                return false;
                            }else{
                                alert("分配成功");
                            }
//                            window.localStorage.setItem("orderData", null);
//                            window.localStorage.setItem("measureData", null);
                            window.location.href = "/wechat/workflow/index/type/{$workorder.workorder_type}";
                        },
                    })

                },
                examOrder: function() {
                    var workorderId = $("input[name=workorderId]").val();
//                    var patientCompleted = $("input[name=patientCompleted]").val();
                    var examBasicCompleted = $("input[name=examBasicCompleted]").val();
                    var examBasicCPCompleted = $("input[name=examBasicCPCompleted]").val();
                    var examMeasureCompleted = $("input[name=examMeasureCompleted]").val();
//                    var examMeasureCompleted2 = $("input[name=examMeasureCompleted2]").val();
//                    var examAnalysisCompleted = $("input[name=examAnalysisCompleted]").val();
//                    var examinatorId = $("select[name=examinatorId]").val();

//                    if(isNullOrEmpty(patientCompleted)) {
//                        alert("患者基本资料未完善");
//                        return false;
//                    }
                    if(isNullOrEmpty(examBasicCompleted)) {
                        alert("检测(评估)信息未完善");
                        return false;
                    }
//                    if(isNullOrEmpty(examBasicCPCompleted)) {
//                        alert("检测(物理)信息未完善");
//                        return false;
//                    }
                    if(isNullOrEmpty(examMeasureCompleted)) {
                        alert("检测(测量)信息未完善");
                        return false;
                    }
//                    if(isNullOrEmpty(examMeasureCompleted2) && "{$workorder.workorder_type}" == 2) {
//                        alert("数字化绘制未完善");
//                        return false;
//                    }
//                    if(isNullOrEmpty(examAnalysisCompleted)) {
//                        alert("检测(处方)信息未完善");
//                        return false;
//                    }
//                    if(isNullOrEmpty(examinatorId)) {
//                        alert("未选择检测评估矫形师");
//                        return false;
//                    }
                    var data = {};

                    data.workorderId = workorderId;
//                    data.patientCompleted = patientCompleted;
//                    data.examBasicCompleted = examBasicCompleted;
//                    data.examMeasureCompleted = examMeasureCompleted;
//                    data.examAnalysisCompleted = examAnalysisCompleted;
//                    data.examinatorId = examinatorId;

                    $.ajax({
                        url:"/wechat/workorder/examOrder",
                        type:"post",
                        data:data,
                        dataType:"JSON",
                        beforeSend:function(){
                            $("#loadingToast").show();
                        },
                        complete:function(){
                            $('#loadingToast').hide();
                        },
                        success:function(data){
                            if(data.code != 200) {
                                alert(data.msg);
                                return false;
                            }else{
                                alert("检测成功");
                            }
//                            window.localStorage.setItem("orderData", null);
//                            window.localStorage.setItem("measureData", null);
                            window.location.href = "/wechat/workflow/index/type/{$workorder.workorder_type}";
                        },
                    })

                },
                submitOrder: function() {
                    var workorderId = $("input[name=workorderId]").val();
                    var typeName = $("input[name=typeName]").val();
                    var deposit = $("input[name=deposit]").val();
                    var price = $("input[name=price]").val();
                    var deliveryDate = $("input[name=deliveryDate]").val();
                    var adapt = $("select[name=adapt]").val();
                    var prescriberId = $("select[name=prescriberId]").val();

//                    if(isNullOrEmpty(prescriberId)) {
//                        alert("未选择处方师");
//                        return false;
//                    }
                    if(isNullOrEmpty(typeName)) {
                        alert("未填写种类");
                        return false;
                    }
                    if(isNullOrEmpty(deposit)) {
                        alert("未填写预付款");
                        return false;
                    }
                    if(isNullOrEmpty(price)) {
                        alert("未填写订单价格");
                        return false;
                    }
                    if(isNullOrEmpty(deliveryDate)) {
                        alert("未填写预计交货日期");
                        return false;
                    }
                    if(isNullOrEmpty(adapt)) {
                        alert("未填适配方式");
                        return false;
                    }

                    var data = {};

                    data.workorderId = workorderId;
                    data.typeName = typeName;
                    data.deposit = deposit;
                    data.price = price;
                    data.deliveryDate = deliveryDate;
                    data.adapt = adapt;
                    data.prescriberId = prescriberId;

                    $.ajax({
                        url:"/wechat/workorder/submitOrder",
                        type:"post",
                        data:data,
                        dataType:"JSON",
                        beforeSend:function(){
                            $("#loadingToast").show();
                        },
                        complete:function(){
                            $('#loadingToast').hide();
                        },
                        success:function(data){
                            if(data.code != 200) {
                                alert(data.msg);
                                return false;
                            }else{
                                alert("工单提交成功");
                            }
//                            window.localStorage.setItem("orderData", null);
//                            window.localStorage.setItem("measureData", null);
                            window.location.href = "/wechat/workflow/index/type/{$workorder.workorder_type}";
                        },
                    })

                },
                closeOrder: function() {
                    var workorderId = $("input[name=workorderId]").val();
                    var closeReason = $("textarea[name=closeReason]").val();

                    if(isNullOrEmpty(closeReason)) {
                        alert("未填写关闭原因");
                        return false;
                    }
                    if(!confirm("关闭工单后，工单内容将被删除，是否继续？")){
                        return false;
                    }
                    var data = {};
                    data.workorderId = workorderId;
                    data.closeReason = closeReason;

                    $.ajax({
                        url:"/wechat/workorder/closeOrder",
                        type:"post",
                        data:data,
                        dataType:"JSON",
                        beforeSend:function(){
                            $("#loadingToast").show();
                        },
                        complete:function(){
                            $('#loadingToast').hide();
                        },
                        success:function(data){
                            if(data.code != 200) {
                                alert(data.msg);
                                return false;
                            }else{
                                alert("工单关闭成功");
                            }
//                            window.localStorage.setItem("orderData", null);
//                            window.localStorage.setItem("measureData", null);
                            window.location.href = "/wechat/workflow/index/type/{$workorder.workorder_type}";
                        },
                    })

                },
                storageOrder: function() {
                    var workorderId = $("input[name=workorderId]").val();
                    var batchNo = $("input[name=batchNo]").val();
                    var data = {};

                    data.workorderId = workorderId;
                    data.batchNo = batchNo;

                    $.ajax({
                        url:"/wechat/workorder/storageOrder",
                        type:"post",
                        data:data,
                        dataType:"JSON",
                        beforeSend:function(){
                            $("#loadingToast").show();
                        },
                        complete:function(){
                            $('#loadingToast').hide();
                        },
                        success:function(data){
                            if(data.code != 200) {
                                alert(data.msg);
                                return false;
                            }else{
                                alert("入库成功");
                            }
//                            window.localStorage.setItem("orderData", null);
//                            window.localStorage.setItem("measureData", null);
                            window.location.href = "/wechat/workflow/index/type/{$workorder.workorder_type}";
                        },
                    })

                },
                endOrder: function() {
                    var workorderId = $("input[name=workorderId]").val();

                    var data = {};

                    data.workorderId = workorderId;


                    $.ajax({
                        url:"/wechat/workorder/endOrder",
                        type:"post",
                        data:data,
                        dataType:"JSON",
                        beforeSend:function(){
                            $("#loadingToast").show();
                        },
                        complete:function(){
                            $('#loadingToast').hide();
                        },
                        success:function(data){
                            if(data.code != 200) {
                                alert(data.msg);
                                return false;
                            }else{
                                alert("工单完成");
                            }
//                            window.localStorage.setItem("orderData", null);
//                            window.localStorage.setItem("measureData", null);
                            window.location.href = "/wechat/workflow/index/type/{$workorder.workorder_type}";
                        },
                    })

                }
            }
        });
        $("select[name=paymentStatus]").change(function() {
            if($(this).val() == "已付定金") {
                $(".deposit").show();
            } else {
                $(".deposit").hide();
            }
        });
        if($("select[name=paymentStatus]").val() == "已付定金"){
            $(".deposit").show();
        }
        $("select[name=adapt]").change(function() {
            if($(this).val() == "快递") {
                $(".delivery").show();
            } else {
                $(".delivery").hide();
            }
        });
        if($("select[name=adapt]").val() == "快递"){
            $(".delivery").show();
        }
        $("select[name='client_info_id']").change(function () {
            var id = $("select[name='client_info_id']").val();
            var listArr=<?php echo json_encode($listClientInfo);?>;
            var list=eval(listArr);
            for(var i=0;i<list.length;i++){
                if(list[i]["client_info_id"] == id){
//                    $("input[name=minimum_percent]").val(list[i]["minimum_percent"]*100);
                    if($("select[name='client_info_id']").find("option:selected").text() == "个人客户"){
                        break
                    }
                    $("input[name=receiveName]").val(list[i]["contact"]);
                    $("input[name=receiveContact]").val(list[i]["mobile"]);
                    $("input[name=receiveAddress]").val(list[i]["address"]);
                    break;
                }
            }

        });
        $(".item select").change(function() {
            var value = $(this).find("option:selected").text();
            $(this).prev().val(value);
        });
        $("textarea").keypress(function(e) {
            if (e.which == 13) {
                return false;
            }
        });
        $("#checkClose").change(function() {
            if($(this).is(":checked")){
                $("#closeButton").show();
                $("#submitButton").hide();
                $("#closeReason").show();
//                $("textarea[name=closeReason]").focus();
                var h = $(document).height()-$(window).height();
                $(document).scrollTop(h);
            }else{
                $("#closeButton").hide();
                $("#submitButton").show();
                $("#closeReason").hide();
            }
        });
    })

</script>

<div class="container" id="container">
    <div class="hint-info">
        <span class="workorder_no">{$workorder.workorder_no}</span>
        <if condition="$workorder['status'] eq '-1'">
            <span class="workorder_examinator">创建于：{$workorder.create_time}</span>
        </if>
        <if condition="$workorder['status'] eq '1'">
            <span class="workorder_examinator">建单于：{$workorder.update_time}</span>
        </if>
        <if condition="$workorder['status'] eq '2'">
            <span class="workorder_examinator">派单于：{$workorder.dispatch_time}</span>
        </if>
        <if condition="$workorder['status'] eq '3'">
            <span class="workorder_examinator">接单于：{$workorder.submit_time}</span>
        </if>
    </div>
    <div class="workorder-info">
        <input type="text" style="display: none;" name="workorderId" value="{$workorder.workorder_id}">
        <div class="item" v-on:click="patientInfo({$workorder.workorder_id})">
            <span>患者信息 {$workorder.side}</span>
            <if condition="$patientInfo['completed'] eq '-1'">
                <input type="text" name="patientData" readonly placeholder="患者基本资料未完善">
                <img class="icon-ok" src="/Template/images/icon-error.png" alt="">
                <img class="icon-right" src="/Template/images/icon-right.png" alt="">
            <elseif condition="$patientInfo['completed'] eq 1"/>
                <input type="text" style="display: none;" name="patientCompleted" value="{$patientInfo.completed}">
                <input type="text" name="patientData" readonly placeholder="患者基本资料已完善">
                <img class="icon-ok" src="/Template/images/icon-ok.png" alt="">
                <img class="icon-right" src="/Template/images/icon-right.png" alt="">
            <else/>
                <input type="text" name="patientData" readonly placeholder="请填写患者基本资料">
                <img class="icon-ok" src="/Template/images/icon-warn.png" alt="">
                <img class="icon-right" src="/Template/images/icon-right.png" alt="">
            </if>
        </div>
        <div class="item" v-on:click="examBasic({$workorder.workorder_id})" v-if="{$workorder.workorder_type} != 3">
            <span>检测评估</span>
            <if condition="$examBasicInfo['completed'] eq '-1'">
                <input type="text" name="" readonly placeholder="检测评估信息未完善">
                <img class="icon-ok" src="/Template/images/icon-error.png" alt="">
                <img class="icon-right" src="/Template/images/icon-right.png" alt="">
            <elseif condition="$examBasicInfo['completed'] eq '1'"/>
                <input type="text" style="display: none;" name="examBasicCompleted" value="{$examBasicInfo.completed}">
                <input type="text" name="" readonly placeholder="检测评估信息已完善">
                <img class="icon-ok" src="/Template/images/icon-ok.png" alt="">
                <img class="icon-right" src="/Template/images/icon-right.png" alt="">
            <else/>
                <input type="text" name="" readonly placeholder="请填写检测评估信息">
                <img class="icon-ok" src="/Template/images/icon-warn.png" alt="">
                <img class="icon-right" src="/Template/images/icon-right.png" alt="">
            </if>
        </div>
        <div class="item" v-on:click="examBasicCP({$workorder.workorder_id})" v-if="{$workorder.workorder_type} == 1 || {$workorder.workorder_type} == 3">
            <span>物理检查</span>
            <if condition="$examBasicCPInfo['completed'] eq '-1'">
                <input type="text" name="" readonly placeholder="物理检查信息未完善">
                <img class="icon-ok" src="/Template/images/icon-error.png" alt="">
                <img class="icon-right" src="/Template/images/icon-right.png" alt="">
                <elseif condition="$examBasicCPInfo['completed'] eq 1"/>
                <input type="text" style="display: none;" name="examBasicCompleted" value="{$examBasicInfo.completed}">
                <input type="text" name="" readonly placeholder="物理检查信息已完善">
                <img class="icon-ok" src="/Template/images/icon-ok.png" alt="">
                <img class="icon-right" src="/Template/images/icon-right.png" alt="">
                <else/>
                <input type="text" name="" readonly placeholder="请填写物理检查信息">
                <img class="icon-ok" src="/Template/images/icon-warn.png" alt="">
                <img class="icon-right" src="/Template/images/icon-right.png" alt="">
            </if>
        </div>
        <div class="item" v-on:click="examMeasure({$workorder.workorder_id})" v-if="{$workorder.workorder_type} != 3">
            <span>检查测量</span>
            <if condition="$examMeasureInfo['completed'] eq '-1'">
                <input type="text" name="" readonly placeholder="检测测量信息未完善">
                <img class="icon-ok" src="/Template/images/icon-error.png" alt="">
                <img class="icon-right" src="/Template/images/icon-right.png" alt="">
            <elseif condition="$examMeasureInfo['completed'] eq 1"/>
                <input type="text" style="display: none;" name="examMeasureCompleted" value="{$examMeasureInfo.completed}">
                <input type="text" name="" readonly placeholder="检测测量信息已完善">
                <img class="icon-ok" src="/Template/images/icon-ok.png" alt="">
                <img class="icon-right" src="/Template/images/icon-right.png" alt="">
            <else/>
                <input type="text" name="" readonly placeholder="请填写检测测量信息">
                <img class="icon-ok" src="/Template/images/icon-warn.png" alt="">
                <img class="icon-right" src="/Template/images/icon-right.png" alt="">
            </if>
        </div>
        <div class="item" v-on:click="examMeasureSpineDraw({$workorder.workorder_id})" v-if="{$workorder.workorder_type} == 2" >
            <span>脊柱侧弯畸形数字化绘制</span>
            <img class="icon-right" src="/Template/images/icon-right.png" alt="">

        </div>
        <!--div class="item" style="display: none">
            <span>生产批号：</span>
            <input name="batchNo" type="text" value="{$workorder.batch_no}" placeholder="请输入">
        </div-->
        <!--div class="item" v-on:click="examAnalysis({$workorder.workorder_id})">
            <span>处方</span>
            <if condition="$examAnalysisInfo['completed'] eq '-1'">
                <input type="text" name="" readonly placeholder="检测处方信息未完善">
                <img class="icon-ok" src="/Template/images/icon-error.png" alt="">
                <img class="icon-right" src="/Template/images/icon-right.png" alt="">
                <elseif condition="$examAnalysisInfo['completed'] eq 1"/>
                <input type="text" style="display: none;" name="examAnalysisCompleted" value="{$examAnalysisInfo.completed}">
                <input type="text" name="" readonly placeholder="检测处方信息已完善">
                <img class="icon-ok" src="/Template/images/icon-ok.png" alt="">
                <img class="icon-right" src="/Template/images/icon-right.png" alt="">
                <else/>
                <input type="text" name="" readonly placeholder="请填写检测处方信息">
                <img class="icon-ok" src="/Template/images/icon-warn.png" alt="">
                <img class="icon-right" src="/Template/images/icon-right.png" alt="">
            </if>
        </div-->
        <div class="item" v-if="{$workorder.workorder_type} != 3">
            <span>业务员：</span>
            <input id="salesId" type="text" value="{$sales.admin_name}" readonly placeholder="请选择业务员">
            <select name="salesId" v-if="{$workorder.status} == -1 || checkRole('{$role}', '1')">
                <option value="{$sales.employee_id}">请选择</option>
                {:getEmployeeSelectOptionHtml($user['enterprise_code'],"2",2)}
            </select>
            <img class="icon-right" src="/Template/images/icon-right.png" alt="" v-if="{$workorder.status} == -1 || checkRole('{$role}', '1')">
        </div>
        <!--div class="item" v-if="{$workorder.status} >= 2" >
            <span>检测评估矫形师：</span>
            <input id="examinatorId" type="text" value="{$examinator.employee_name}" readonly placeholder="请选择检测人员">
            <select name="examinatorId" v-if="{$workorder.status} == 2 && {$job.0} == 4 && '{$workorder.exam_time}' == ''" >
                <option value="">请选择</option>
                {:getEmployeeSelectOptionHtml(1,2,2)}
            </select>
            <img class="icon-right" src="/Template/images/icon-right.png" alt="" v-if="{$workorder.status} == 2 && '{$workorder.examinator_id}' == ''">
        </div-->
        <div class="item" v-if="{$workorder.workorder_type} != 3">
            <span>处方人：</span>
            <input id="prescriberId" type="text" value="{$prescriber.admin_name}" readonly placeholder="请选择出处方人">
            <select name="prescriberId" v-if="{$workorder.status} <= 2 || checkRole('{$role}', '1')">
                <option value="{$prescriber.employee_id}">请选择</option>
                {:getEmployeeSelectOptionHtml($user['enterprise_code'],"6",2)}
            </select>
            <img class="icon-right" src="/Template/images/icon-right.png" alt="" v-if="{$workorder.status} <= 2 || checkRole('{$role}', '1')">
        </div>
        <div v-if="{$workorder.status} >= -1 && {$workorder.workorder_type} != 3">
            <div class="item">
                <span>检测评估矫形师：</span>
                <input id="examinatorId" type="text" value="{$examinator.admin_name}" readonly placeholder="请选择检测人员">
                <select name="examinatorId" v-if="{$workorder.status} <= 2 || checkRole('{$role}', '1')">
                    <option value="{$examinator.employee_id}">请选择</option>
                    {:getEmployeeSelectOptionHtml($user['enterprise_code'],"5",2)}
                </select>
                <img class="icon-right" src="/Template/images/icon-right.png" alt="" v-if="{$workorder.status} <= 2 || checkRole('{$role}', '1')">
            </div>
            <!--div class="item">
                <span>已收预付款：</span>
                <input name="depositOri" type="text" value="{$workorder.deposit}" placeholder="请输入">
            </div-->
        </div>
        <!--div class="item">
            <span>初定矫形器类型：</span>
            <input name="typeNameOri" type="text" value="{$workorder.type_name}" placeholder="请输入">
        </div-->

        <div class="item">
            <span>订单价格：</span>
            <input name="price" type="text" value="{$workorder.price}" placeholder="请输入">
        </div>
        <div v-if="{$workorder.workorder_type} != 3">
            <div class="item">
                <span v-if="{$workorder.workorder_type} <= 7">矫形器种类：</span>
                <span v-if="{$workorder.workorder_type} >= 8">假肢种类：</span>
                <input name="typeName" type="text" value="{$workorder.type_name}" placeholder="请输入">
            </div>
            <div class="item">
                <span>付款情况：</span>
                <input id="paymentStatus" type="text" value="{$workorder.payment_status}" readonly placeholder="请选择">
                <select style="width: 120px" name="paymentStatus">
                    <option value="{$workorder.payment_status}">请选择</option>
                    {:getFormDictSelectOption($workorder['payment_status'],'paymentStatus','all',0)}
                </select>
                <img class="icon-right gender" src="/Template/images/icon-right.png" alt="">
            </div>
            <div class="item deposit" style="display: none">
                <span>定金：</span>
                <input name="deposit" type="text" value="{$workorder.deposit}" placeholder="请输入">
            </div>
            <div class="item">
                <span>预计交货时间：</span>
                <input name="deliveryDate" type="text" value="{$workorder.delivery_date}" placeholder="请输入">
            </div>
        </div>
        <div class="item" v-if="checkRole('{$role}', '1')">
            <span>下单人：</span>
            <input id="creatorId" type="text" value="{$creator.admin_name}" readonly placeholder="请选择下单人">
            <select name="creatorId" v-if="checkRole('{$role}', '1')">
                <option value="{$creator.employee_id}">请选择</option>
                {:getEmployeeSelectOptionHtml($user['enterprise_code'],"0",0)}
            </select>
            <img class="icon-right" src="/Template/images/icon-right.png" alt="" v-if="checkRole('{$role}', '1')">
        </div>
        <div class="item">
            <span>客户：</span>
            <input id="client_info_id" type="text" value="{$workorder.client_info_name}" readonly placeholder="请选择">
            <select name="client_info_id">
                {:getCommonSelectOptionHtml($workorder['client_info_id'], "ClientInfo", "client_info_id", "client_info_name", null, $user['enterprise_code'], 1)}
            </select>
            <img class="icon-right gender" src="/Template/images/icon-right.png" alt="">
        </div>
        <div class="item">
            <span>适配方式：</span>
            <input id="adapt" type="text" value="{$workorder.adapt}" readonly placeholder="请选择">
            <select style="width: 120px" name="adapt">
                <option value="{$workorder.adapt}">请选择</option>
                {:getFormDictSelectOption($workorder['adapt'],'adapt','all',0)}
            </select>
            <img class="icon-right gender" src="/Template/images/icon-right.png" alt="">
        </div>
        <div class="delivery" style="display: none">
            <div class="item">
                <span>收货人姓名</span>
                <input type="text" name="receiveName" value="{$workorder.receive_name}" placeholder="请填写收货人姓名">
                <img class="icon-right" src="/Template/images/icon-right.png" alt="">
            </div>
            <div class="item">
                <span>收货人电话</span>
                <input type="text" name="receiveContact" value="{$workorder.receive_contact}" placeholder="请填写收货人电话">
                <img class="icon-right" src="/Template/images/icon-right.png" alt="">
            </div>
            <div class="item receiveAddress">
                <span>收货地址</span>
                <input type="text" name="receiveAddress" value="{$workorder.receive_address}" placeholder="请填写收货地址">
                <img class="icon-right" src="/Template/images/icon-right.png" alt="">
            </div>
        </div>
        <div class="item" v-if="{$workorder.workorder_type} != 3">
            <span>工单状态：</span>
            <php>
                $statusName = $formDict["status_".$workorder["status"]];
            </php>
            <input id="statusId" type="text" value="{$statusName}" readonly placeholder="请选择">
            <select name="statusId" v-if="checkRole('{$role}', '1')" >
                <option value="{$workorder.status}">请选择</option>
                {:getFormDictSelectOptionHtml($workorder['status'],'status','all',0)}
            </select>
            <img class="icon-right" src="/Template/images/icon-right.png" alt="" v-if="checkRole('{$role}', '1')" >
        </div>
        <php>
            if($workorder["status"] == -1 && ($workorder["workorder_type"] == 1 || $workorder["workorder_type"] == 5 || $workorder["workorder_type"] == 6 || $workorder["workorder_type"] == 7)){
                $workorderList = D("Workorder")->order("create_time desc")->where(array('patient_id'=>$workorder["patient_id"]))->limit("0,2")->select();
                $lastWorkorder = $workorderList[1];
                $days = (time()-strtotime($lastWorkorder["create_time"]))/86400;
                $showDuplicate = 0;
                if($days > 30){
                    $showDuplicate = 1;
                }
            }
        </php>
        <div v-if="{$showDuplicate} == 1">
            <div class="checkline">
                <input class="checkFirst" id="duplicate" value="0" type="checkbox" ><a style="color: #F96E57; font-weight: bold">复制本工单内容并生成对侧患肢工单</a>
            </div>
            <div class="line"></div>
        </div>
        <div v-if="{$workorder.status} == 2 && checkRole('{$role}', '1')">
            <div class="checkline">
                <input class="checkFirst" id="checkClose" value="0" type="checkbox" >问题工单
            </div>
            <div class="item" id="closeReason" style="display: none; ">
                <span>关闭原因：</span>
                <textarea class="t-area" name="closeReason" maxlength="120" placeholder="请填写">{$workorder.close_reason}</textarea>
            </div>
            <div class="line"></div>
        </div>

    </div>
    <div class="order-operation">
        <div v-if="{$workorder.status} > -1 && checkRole('{$role}', '1')">
            <button class="save-btn" v-on:click="changeStatus">修改状态</button>
        </div>
        <button class="cancel-btn" v-on:click="returnOrder">返回</button>
        <div v-if="{$workorder.status} == -1 && {$workorder.creator_id} == {$customerId} && {$workorder.workorder_type} != 3">
            <button class="save-btn" v-on:click="createOrder">提交工单</button>
        </div>
        <div v-if="{$workorder.status} == -1 && {$workorder.creator_id} == {$customerId} && {$workorder.workorder_type} == 3">
            <button class="save-btn" v-on:click="createOrder">保存检查表</button>
        </div>
        <!--if condition="$workorder['status'] eq '1' && $job[0] eq 3">
            <button class="save-btn" v-on:click="dispatchOrder">派单</button>
        </if-->
        <div id="submitButton" v-if="{$workorder.status} == 2 && checkRole('{$role}', '5')">
            <button class="save-btn" v-on:click="submitOrder">提交工单</button>
        </div>
        <!--div v-if="{$workorder.status} == 3 && checkRole('{$role}', '3') && $workorder.storage_time} == ''">
            <button class="save-btn" v-on:click="storageOrder">可以发货</button>
        </div-->
        <!--div-- v-if="{$workorder.status} == 3 && checkRole('{$role}', '3')">
            <button class="save-btn" v-on:click="endOrder">完成工单</button>
        </div-->
        <div id="closeButton" style="display: none"  v-if="{$workorder.status} == 2 && checkRole('{$role}', '1')">
            <button class="close-order" v-on:click="closeOrder">关闭工单</button>
        </div>

    </div>

</div>
<include file="./Template/footer.html" />